// This file needs mpic++ for compilation

#include <iostream>
#include <string>
#include <imcmc/imcmc.hpp>
#include <imcmc/parser++.hpp>
#include "SNE.hpp"
#include "CosmoTheory.hpp"


using namespace std;
using namespace imcmc;
using namespace imcmc::parser;

int main( int argc, char* argv[] ){

	MPI::Init(argc,argv);

	if( argc < 2 ){
		cout << "usage: " << argv[0] << " param.ini" << endl;
		MPI::Finalize();
		exit(0);
	}

	string inifile = string(argv[1]);
	string snls3_dataset = Read::Read_String_from_File(inifile,"SNLS_dataset");

	SNe_SNLS snls3;
	snls3.Init(snls3_dataset);

	imcmc_double par;

	double alpha_snls3 = Read::Read_Double_from_File(inifile,"alpha_snls");
	double beta_snls3 = Read::Read_Double_from_File(inifile,"beta_snls");

	par["alpha_snls"] = alpha_snls3;
	par["beta_snls"]  = beta_snls3;

	cout << "ready to compute the total covariance matrix for:\n"
		 << " \'alpha = " << alpha_snls3 << "\'\n"
		 << " \'beta  = " << beta_snls3 << "\'" << endl;

	snls3.UpdateNuisance(par);
	snls3.UpdateCov();

	string rootname = "snls3_cov_"; 
	rootname += "alpha=";
	rootname += Read::DoubleToString(alpha_snls3);
	rootname += "_" ;
	rootname += "beta=";
	rootname += Read::DoubleToString(beta_snls3); 
	snls3.SaveTotalCov(rootname);

	cout << "Total covariance matrix and its inverse have been save into:\n"
		 << rootname + ".txt" << " and  "
		 << rootname + "_inv.txt" << endl;

	MPI::Finalize();
}
